/*
 * =====================================================================================
 *
 *       Filename:  rbtree.h
 *
 * =====================================================================================
 */

/* rbtree.c */
#include <stdint.h>
#include <stdlib.h>

#ifndef __RBTREE_HEAD
#define __RBTREE_HEAD

typedef struct rbtree_t rbtree_t;
typedef struct rbnode_t rbnode_t;
        
rbtree_t       *rbtree_create(int (*Compare)(const void *, const void *),
                               void (*freeNode)(void *),
                               int replace_flag);
void            rbtree_free(rbtree_t *tree);
int             rbtree_insert(rbtree_t *tree, void *Data);
rbnode_t        *rbtree_insertnode(rbtree_t *tree, void *Data);
void            rbtree_delete(rbtree_t *tree, rbnode_t *Z);
int             rbtree_deletebydata(rbtree_t *tree, const void *data);
rbnode_t       *rbtree_find(rbtree_t *tree, const void *Data);
void           *rbtree_finddata(rbtree_t *tree, const void *Data);
int             rbtree_num_elements(rbtree_t *tree);
void           *rbtree_min(rbtree_t *tree);
void           *rbtree_node2data(rbtree_t *tree, rbnode_t *node);

/* callback order for walking  */
typedef enum { PreOrder, InOrder, PostOrder } RBTREE_ORDER;

#endif
